package com.lesson02;

import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class TestKeyListener {
    public static void main(String[] args) {
        new KeyFrame();
    }
}
class KeyFrame extends Frame {
    public KeyFrame(){
        setBounds(300,300,200,150);
        setVisible(true);
        this.addKeyListener(new KeyAdapter(){
            //键盘被按下
            @Override
            public void keyPressed(KeyEvent e) {
                int keyCode = e.getKeyCode();
                if(keyCode == KeyEvent.VK_UP)
                    System.out.println("上");
                System.out.println("按下了"+e.getKeyCode()+"键");
            }
        });
    }
}